import request from '@/utils/request'

// 公开接口
/**
 * 获取文章列表
 */
export const getArticles = (params) => {
  return request({
    url: '/articles',
    method: 'get',
    params
  })
}

/**
 * 获取文章详情
 */
export const getArticleDetail = (id) => {
  return request({
    url: `/articles/${id}`,
    method: 'get'
  })
}

/**
 * 获取首页推荐内容
 */
export const getHomeRecommended = () => {
  return request({
    url: '/articles/home/recommended',
    method: 'get'
  })
}

/**
 * 获取热门文章
 */
export const getHotArticles = (params) => {
  return request({
    url: '/articles/hot',
    method: 'get',
    params
  })
}

/**
 * 记录文章浏览
 */
export const viewArticle = (id) => {
  return request({
    url: `/articles/${id}/view`,
    method: 'post'
  })
}

// 管理员接口
/**
 * 获取文章列表（管理）
 */
export const getArticleList = (params) => {
  return request({
    url: '/admin/articles',
    method: 'get',
    params
  })
}

/**
 * 创建文章
 */
export const createArticle = (data) => {
  return request({
    url: '/admin/articles',
    method: 'post',
    data
  })
}

/**
 * 更新文章
 */
export const updateArticle = (data) => {
  return request({
    url: `/admin/articles/${data.id}`,
    method: 'put',
    data
  })
}

/**
 * 删除文章
 */
export const deleteArticle = (id) => {
  return request({
    url: `/admin/articles/${id}`,
    method: 'delete'
  })
}